Bug fixes and speed improvements