Attempt to refactor; not working