refactoring function calls - still an awful lot needs doing here