Fixed a bug in neighbor list construction

This fixes #712.