Fragment refactoring
Various fixes and improvements