Fixed some bugs. Now should be cross platform. Macs except weird code

This pull request is for teh bugs.