add functions #1
fixed various copy&paste bugs