restructured some stuff to make it more dry