fixed formatting to minimize diff
formatted, commented and cleaned code