bugfix and clean up