bugs fixed, output refined a little bit