Fix some bugs

I'll do something more here, so do not pull yet.

* Fix #335 
* Fix #367
* Fix #368
* The debug window (where you can change variables and switches) will now refresh the map events