Splitted math code into header and impl.