improved the script for general purposes