fixed bugs which stopped more than one command being sent, refactored parsing code