Added defensive programming support (not fully tested yet)