added cuda state check