Added stats gathering; other cleanup.
Added math library (-lm).