I've replaced the next function with in-line code, but I think that in-line code should check if there is an error before modifying at and ch.