rm pseudo-code appended and a general test code added.