Made connection persistent and addede a factory for commands.