New optimized fill function