god this code is weird. tidying some stuff up