Fixing divide by zero error for ptr