Refactored design and some code