refactor and improvement