updated and tested, now a working script