Reorganisation and bug fixes