removed leak in single factor
cleaning up code
last tested version