Cleaned up code & fixed some errors