reordered and reformatted code