Just so you know, you do not need to explicitly need to check for true, false, or nil in Lua. For readability, these are the same.
Code:
-- the value is true
if a == true then ...
if a ~= false then ...
if a ~= nil then ...
if a then ... <-- use this!
-- the value is false or nil
if a == false then ...
if a == nil then ...
if a ~= true then ...
if not a then ... <-- use this!
Only explicitly check if the value of a can be tri-state, like true/false/nil or 1/0/nil.