optimize offset/limit usage & refactor js code a bit