Refactor to consolidate code. Not done yet.