Added version with fewer lines, but is slower