rewrote pretty much everything