some refactoring
fix some problems
maybe fix crosstalk problem
refactoring from util.py