Fixed bad loop and bad calling to print function