refactoring code to use object initialiser