Fix optimization conditions & update scala docs to explain.