with changes, need last two functions debugged