moved errorhandling into two different functions