Fixed javadoc, removed useless casts, Prevented some npes.