Working implementation with test