Implemented splitting and fixed some bugs