Fixed nil reference issue