Cleanup

Cleaned up the code, fixed some errors.