Improve performance of scanl (thanks @MigMit@)