Somewhat functional code; not done yet