Restructured code a little bit.