Refactor code based on Thong Nguyen comment