hopefully complete, cleaned, with debugging statements