fixed the server bug for getting the cap value and added some memory cleanup