Fixed bug wrongly resetting states. Added error dialog.