speeding things up, refactoring