updated for error handling