Function gets called twice