moved functions to module exports, rewrote some functionality and cleaned some things
test