similartiy: moved interesting reusable code into header