fixed and re written parts of the code to use the new or different functions