change order of operations to be more sensible