Switch back to prepend and use foldl instead.