Refactored code to reduce code duplication.
Improved also input field validation in the constructors as part of the same change.