i write messy code but here it is