Better error handling, and implementations of the ack and nack functions