Pie: Use safer resource handling