Refactoring and tidying of the code.