updated code to match derick bailey's repo