Slightly more optimized version