Fixed a few issues with the maths, ZSH does not do zero-index arrays.