Refactored + speed optimized