fixed nil error

will not work correctly without that fix.