Extensive improvements to layout and backend