lots of refactoring, prep for rails 4.2