fixes and speed improvements