refactor and improve.