Cleanup
Move some code around