refactor rtl code