bug fixes to sorting network

Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>