added protection against negative values for speed