added validation, fixed errors