refactor and design improvements