bugfix and some cleanup