fixed next step algorithm + some documentation