add --direction option and some refactoring