It seems weird passing loc in here just so it can be used in one of the cases, but I can't really think of a better way right now.