reworking some error handling