Added exceptions to check if input is valid