clean up functions and make some private