add variable status checking, a bit more cleanup