Fixes bugs in the fragment switching