completed refactor, but will need cleanup