start of major refactor, make code more sane