added validation, code impovements