refactor and improve