Some modularity; general cleanup of codebase