Restructured some code