some algorithms coded in java, for later use