Added JavaDoc and reformatted code