Restructured code a bit more