Refactored code; exception form only occurs in release mode