refactored everything into more OO design