Refartoring
Fixed some bugs