Fixed incorrect row/column calculation in Firefox

Added a tiny hack for Firefox issue in calculating width.
Also, added a better way of calculating rows and columns that takes care of several corner cases.

Fixes #9