Fixed contact popup bug and reorganized javascript