documented, minor changes in logic