Fix bugs in LIMIT clause