copied a couple of solutions from Internet