added more theory, and finally started doing some reasonable code: