Bug fix in pinning code