Issue #182. Hardcoded 'localhost' removed

This code does the same as previous version, but removes hardcoded "localhost".