Some refactor. Still a mess up.