added a bit of errorhandling