Tweaks some measurement and layout stuff and fixes a potential NPE.