performance tweaks. Fixed if not exists for creating index bug.