Cleanup and standardize server commands, fix memleak