modified code with check gates to validate user entries