Fixing the NullPointerException problems.