The calcZP function is all psuedo code