AJAX refactoring

 rebased against 41d8cd3d8827d9fc900a037b0d10554d5d5ddcf9