Getting code folding working and general reorganization