Fixed a bunch of bugs and some memory leaks. Added test case for sync track code
More testing and bugfixing