REFACTOR EXTISTING CODE