refactored clientside js