You wrote this two times, you might consider to factor this in a private check function.