added comments and better formatting