Made top_layer a one-dimensional vector to save a couple bytes and CPU
cycles.