improve \r readability a bit more
move editing code into subroutine