sort methods taken out of somewhere
restructured classes with better design and added javadoc