Changed to Java v. 1.6 and added null checks