Pretty much done

Without spending hours re-working the program this functions properly
and doesn’t have any significant bugs to fix.

Added comments for pretty much everything.