Script debugged and verified working