resource.c: Cleanup and refactor