Bugfix and some improvements