Adjusted the query dialogue to respond to faulty input. Minor refactorings.