massive bugfix and improvement everywhere