minor code refactoring & commenting