Cleaned up return codes, added debug. See NEWS for details.