Fixed two major bugs