Refactor code to use resources