refactor. use between, and deal nan, and refactor frontend