put this check in a sub of itself, and use it everywhere. this is too much code duplication