move reaming functions to class and correct all its references