improved error handling
tested some error handling