Simplified the absolute function

Took advantage of the maths package abs function to reduce the number of lines and make the function easier to read.