Split into functions, put into module