rewrote almost everything