fixed formatting and fully commented