Bug fixed and improved output