Made the script more flexible