Bug fix in SP script