Fixed bugs for 2.6 and rewrote output using proper output functions