massive refactor after watching the solution