Bug fixing and tidying up code.