Fixed a bug in consume function