added statistics, rewrote stats functions)