Added some doc comments and fixed an NPE being thrown in place of an IllegalArgumentException.