moved some functions around.