refactor code to use resource loader