Fix various bugs with LIMIT/OFFSET