Fixed some bugs to work properly