Further code cleanup + restructure