Minor refactoring and added useful user messages.