improved main slightly