Moved whole thing into 2 headers
Various bug and style fixes