fix print result logic;
cleaned up some code.