Adding some input checking. Other minor changes.