Adding loader and fixing some bugs