Add javadocs and error handling