sadly, this code is not as compact, but it gets the job done.