Bugfix and additional checking