Refactor replace_vars: add additional documentation, spell check + code style check