Fixed Various Bugs

See commit for details.