refactoring to remove dupes, few style changes