simplified the code by sacrificing generality, and using @mut was bad anyway