Update API doc, consolidate code and add JavaDoc where necessary