Many many bugfixes

This should make the thing work like a charm!