move impl code into header
more refactoring