Updated 3 and confined common math function to a header file.