improved duplicate handling, added local switching