Fix for popwin
Cleanup code