Re-factored/optimized code