-- some refactoring and statistics computation edit