Added declarations of necessary variables and set things to 0
more declarations
merged copy