Fixed the error issue, as well as cleaned up code in other files, and further commented them