Fixes numerical issues with fmod on internal step