make validate function more monadic