Fixing possible null exception bug