seems ugly code with above same checking.