extract "add prompt to history" functionality
avoid using synchronized(this) {} for extra safety
Fix broken tests.