Tweaks and performace improvements. Added statistics.