Clean up code layout and types