added comments, cleaned code