fixes to layout algoritms