glue: fixed bug in listener ID assignment

Also added simple lifecycle tests.
glue: creationix suggested a good refactor
bugfix and refactoring