I'm always nervous of returns in the middle of functions.  I think actually this code could be pretty cleanly structured as `if (get) ... else if (put) ... else ...`.