Smarter math for get-layout