some refactoring and dealing with &modified buffer (close #27)