Added javadoc and proper error messages