Reworked initialization code, made standard streams extern.