minor code improvements, added test for stats