refactor method based on code-climate comments