merge and refactor