Restructured code to use closures wherever possible for blending & compositing.