Cleaned up some coded, fixed some bugs