change to prevent sqrt of negative number problem