[API] Clean code from core and fix some bugs.