Refactoring resource unpacking routines for better code readability