Fix bug with eliminating gaps