Refactored code. Defined some interfaces, moved some classes, and added javadoc.