Cleaning up code, fixing error messages