repaired code where logic flow error