Refactoring: outsourced methods, added comments, organized code