Refactored level loading into a function