add class instance functions, tune code