Fix for issue #1, resource below zero.
UNTESTED