working version, uncommented validation, removed useless ifs