refactor resource loading