Fixed realign fence bug

Issue #2191