Changed location of lots of flags and conditions, needs testing and more work