Hopefully fixed connection issues and added tests for the desired
behaviour.