Speed up implementation of 'width' function

Fixes #139.