Added maximisation function. It kinda works, I think.