Tidy code and add JavaDocs to SGApi