updated some error handling