Changed printing to avoid looping. Untested