Resources cleanup and refactor