functional version of class code