fixed reference bugs, added print functions