Code clean up and added comments