Refactored require function