Bugfix and consistency checking