Common subexpression elimination

Fix copyrights, formatting (I failed to properly import Eclipse settings into IDEA), class/method naming to your taste.