refactor system code