tested and fixed the script