Changed variable names, moved functions to class