Removed redundant Math.abs in invert function