adding some error checking features to make script more robust. also added package manager detection