fixed client-side code, about to refactor it again