Tidied up client side code