moved code from .c to .h