Catching bugs; restructuring code