adding style and restructuring code