lots of refactoring for consistent style