Fixing null exception bug