added some argument checking to prevent other exceptions