reduce code duplication + remove useless backslash-escaping for #