Added try/catch to release the resources in case there is an exception/error