client javascript reorganization for better readability ;)