reformat and rearrange code
update copyright in java classes to apache license