JAL-4134 tidied up refactoring and fix compilation errrors