Script v1.1 - commented and partly automated