Restructuring code a bit