ugly solution of the first exercise