Added better error handling to OOP implementation