Optimizations by Jose R Valverde (CNB/CSIC)

Improved scripted incorporating optimizations and comments provided by
Jose R Valverde (CNB/CSIC).