rewrote a lot of stuff, everything tested except new delay function