Generally cleaned up code