commented code and fixed malloc bugs