Function seems to work again, halfway trying to simplify things.  #11