split into functions and add comments