Add support for pagination and use proper exit code