fix potential bugs with gaps()