some refactoring and optimization.
implemented mmap input buffer
some refactoring