code outsourced from bornetobe