Flushing out math, needs to be optimised later.