Major fixes. First working version, but still needs adding libraries