modified common code and some minor fixup.