consolidated, cleaned up, and added a simple gap check.