Refactoring to centralise some functions