copied more code that will be needed later for server