Working solution with code to test performance