fix popup outside map + small cleanup and refactoring