few optimisations and behavior corrections