functioning code
merged chagnes