refactor after reviewing solution