Split functions of main.c into buildings.c and memory.c