Added scale listener and minor optimizations.