Moved many functions into modules.