added checking of valid dates