you prob coulda turned all this into a jade function