some bug fixes, minor speed improvements