refractor server side code