Cleaned up main a bit, set everything in a loop