Work in progress. Revisions were made for the sake of readability and efficiency that need to be debugged.