 	
 isAccessible = (username, testPackage, testVersion) ->
 	return true if auth is null
+	
+	# check general packages
 	if auth.packages?
 		for _package, version of auth.packages
 			_package = _package.replace(/([.?*+^$[\]\\(){}|-])/g, "\\$1").replace(/\\\*/, '.*')
 			if RegExp("^#{_package}$", 'i').test testPackage
 				return true if version testVersion
+	
+	# check user
 	if auth.users?[username]?.packages?
 		for _package, version of auth.users[username].packages
 			_package = _package.replace(/([.?*+^$[\]\\(){}|-])/g, "\\$1").replace(/\\\*/, '.*')
 			if RegExp("^#{_package}$", 'i').test testPackage
 				return true if version testVersion
+		# check user groups
 		for group in auth.users[username].groups
 			if auth.groups?[group]?
 				for _package, version of auth.groups[group]

			writer.writeElement 'packagedescription', _package.packageinformation.packagedescription[0]._ ? _package.packageinformation.packagedescription[0]
			writer.writeElement 'isapplication', String(_package.packageinformation.isapplication ? 0)
			do writer.endElement
			if _package.authorinformation?
				writer.startElement 'authorinformation'
				writer.writeElement 'author', _package.authorinformation.author[0] if _package.authorinformation.author[0]?

				writer.startElement 'version'
				writer.writeAttribute 'name', versionNumber
				
				writer.writeAttribute 'accessible', if (isAccessible username, _package.name, versionNumber) then "true" else "false" # TODO: Use proper username
				writer.writeAttribute 'isCritical', if (/pl/i.test versionNumber) then "true" else "false"
				
				# write <fromversions>
				if version.fromversions?.length
					writer.startElement 'fromversions'
					for fromVersion in version.fromversions
						writer.writeElement 'fromversion', fromVersion
					do writer.endElement
				
				# write <requiredpackages>
				if version.requiredpackages?.requiredpackage?.length
					writer.startElement 'requiredpackages'
					for requiredPackage in version.requiredpackages.requiredpackage
						writer.startElement 'requiredpackage'
						writer.writeAttribute 'minversion', requiredPackage.$.minversion if requiredPackage.$?.minversion?
						writer.text requiredPackage._ ? requiredPackage
						do writer.endElement
					do writer.endElement
				
				# write <excludedpackages>
				if version.excludedpackages?.excludedpackage?.length
					writer.startElement 'excludedpackages'
					console.log version.excludedpackages
					for excludedPackage in version.excludedpackages.excludedpackage
						writer.startElement 'excludedpackage'
						writer.writeAttribute 'version', requiredPackage.$.version if excludedPackage.$?.version?
						writer.text excludedPackage._ ? excludedPackage
						do writer.endElement
					do writer.endElement
				
				writer.writeElement 'timestamp', String(Math.floor (do version.timestamp.getTime) / 1000)
				
				# e.g. {{packageServerHost}}/com.example.wcf.test/1.0.0_Alpha_15
