performance tweaks and bugfix