fixed calculation error - wasn't using fabs()