added comments and cleanup