refactor and clean up