refactor and finished plan 1-5