did some refactoring, haflow is easier to be used now