Prevent page break within listings
In the provided example document, listing 4.1 is broken into two pieces spanning three (!) pages due to image placement problems. I think this could be prevented by configuring either the underlying KOMA-script or the listings package (e.g, search for widows, orphans).