Added error information
Replaces math.h by stdlib.h for abs
Added assert