bug fixes. Works for >3 variants