felt like I was cheating using Haskell for this one