Clean up the code, move things around, make it work