Some refactoring to remove inner classes (this causes unexpected crashes with android)
merge with modifs from German