Fixed PInvoke
Cleanup and other stuff added