adding design patterns and general restructuring