modified code, add more validation and removed backup files