Code improvements and bugfixing of discovery service