some juicy refactoring