Parse topic command and replies and clean up the code a bit