Clean up and comment some code, not done yet