small refactors, added comments