Moved maxval function
Functions are now pcalled

That should mean less crashes.