Added and fixed some bugs