Fix Nil reference issue