Adding validation and better error control