Stuffed it all in one function