Fix several bugs & enhancement.