more refactoring
some functions are working!