lastIndex works, compact refactored