Fixed a number of issues.

see issue tracker.