Refactor and commenting