Optimized code as suggested by CI