first attempt at fully functional script
fully functional script. Denis to review output