corrected according to suggestions except tests