making script more robust