some code refactor to increase readability