added better error handling for lua