refactor code, still not stable