Integrated with Habib's code and fixed errors being found