This file should probably have lots of its functionality elsewhere and needs cleaned up as well anyways.