Added config functions.
Added some more (optional) statistics and re-factored some code.