beg, borrow, steal and repurpose code

i used some better code this time