Restructuring functions, hiding some in an internal header file.