Fixing null-ref exception