code sorted into functions