Code ordering; minor performance improvements