added some error catching, changed commandline argument interpretation