working algorithm v0.1