Bugfixes

Fixes for googlecode issue #90, github issue #4 and more.