refactor and enhance