improved nan location discovery, fixes #339