made minor shifts in function order.