BUGFIX: correctly handle unspent outputs