moved code from .cc to .hpp because of template classes.