minor refactoring and bugfixes
stats updates