moved some functions to their own source file.