cleaned code, and added comments