refactored with kevin's help