implemented thinning algorithm