Cleaned up many bugs