refactor while loop
make a recursion more elegant
refactor mt-write-injection-IO