few fixes and speed improvements