Memory bugfixes and optimalizations

- Bugfix in relay protocol that causes a memory leak
- Altered the code so memory allocations are re-used most of the times instead of freeing and allocating all the time
- All clients should now be memory leak and bug free