Refactor this proc.