Trying Tijs' tail recursive method