Refactoring SQL executor

unset variable notice corrected