Added input and error check