Optimizations based on @cobregon feedback