rewrote and simplefied some stuff