Bugfix and error handling