changed few free functions to member functions