implement changes as discussed in #28
improve variable checking