added comments and cleaned code