Refactor, and some design changes