Code simplification, extern fixes