refactor and re-structured