FIx the releasing of resource.
adjusts
Adding Test cases.