Fix a bug where host matching occurs out of order

 * Closes #504