Bug fixed code