Moved server code to the client side for performance.