Code refactored for lazy loading