refactor code slightly