bugfix & do some cleanup