moved stuff into a function