Added the loader and fixed some bugs