Cleaned up command transmission code, added more comments.