added validation as per hw5 requirements