added validation, fixed minor errors