Fix most bugs. (Some bugs in RMERGE_R is remain)

Well. Last commit contains too many bugs. Missing input and wrong fuctions are everywhere.