adds unit tests and tightens validation