Fixes #2905 Added var classes + some factorisation