Clean up code and loose ends