Fixed print function

Fixed all the bugs the print function was having. Tested, but not
thoroughly so.