Cleaned up some code. Did some minor optimizations to the file generation.