added extra_functions and tidied up a few loose ends