fix missing connections
fixed several bugs. tested in practice