put the visibility check in the right place