Calculate width and height better. Fixes #8