optimizations and layouting