added validation, removed unwanted code