Added output functions, some bugs fixed