Cleaned up whitespace
Removed several bugs and cleaned up code