Add option to limit number of connections

Also, add test for this option