Fix a few runtime exceptions resulting in crashes.
Fix ordering of fragment elements