style tweaks, more tail recursion