minor code refactored