commented and (hopefully) cleaned up