now the script works but need refinement