Fixed bugs - divide by 0 and sqrt with -1