added some comments, cleaned some code