Add validation and some unit tests