Refactor code + add javascript api test for pagination #76