Fixing some bugs and upgrade the output