Modified provideResource() and freeResource() methods.
TODO: use the exceptions on these methods