Modified script to make it more generic