more refactor, master still unstable