Further fixes to prevent floating point inaccuracies causeing segfault