added comments and reorganized methods