major code refactor

moved everything into it's own module and decoupled some methods