Updated version. Added stats output.