improve organization and add comments