clean working code(no repetition)