Bugs fixed and output changed