This needs to be refactored...