removed nested if statements, added error messages