Fix: crash in windows plugin, code cleanup