move more functionality into functions