Major rewrite for tablet support