Refactored clientside code