Refactor and comments updated