Refactoring based on Ivan's feedback.