Smaller correct implementation