ported over a lot of stuff