An attempt at doing it generally. Not working 100%