Refactored server to use recursive loop so we need less atoms