refactor marking code