moved error handling