Proper implementation of setLocal.

Plus error handling on failure cases in that method.