UnitTests for Core

Core is now UnitTest-ed, found bugs has been fixed.