minor cleanup, indentation and factoring.