commented m code and did small refactors