added pagination support and grammar recognition