Some design and code refactoring