The lua is map-gen code. It's allowed to be ugly. That is why map-gen code is in lua. Because it's quick to write and not as crucial if it gets ugly.