Fix bug: Test on variable before using it