Cleaned and commented; needs testing/verification
Parts C, B, and A complete