Cleaned up popupmenu code