Fixing nil reference