added math.h for abs and ceil (it was included elswhere)