Added unit-tests and implemented validate method