Various cleanings and optimizations