Needs to be refactored