Reorganized quite a bit of layout stuff and killed some database handle leaks