Stole a solution just for comparison