refactor + minor code modification