Restructure old code