calculate columns only once

Most straightforward fix for #39.