move part of code into .h