First round of bug fixing
Only one error left

However. the one ugliest line of code just got uglier...