replaced scanf with safer method