bugfix & tidying up