Fixed count middle function + tests