added logging and stats