basically copy and pasted code, remove the duplication