Bugfix: fix various bugs