refactor after looking at solucions