minor redesign and refactoring