implemented consuming, refactored a lot of code from cpp files to header files