move code inside central func + move func to its own file