Convert print statements to print function. Fix bugs