cleaned some code and added comments