Fixed Bugs

Fixed various bugs including that the main was stuck in an infinite loop
because of a missing {} set after the while check.