Add javadoc
Reformat + rearange code