Fixed gcor function