major refactor and clean up