Fix resource handling bug