refactor ranwen code