Fixed stackoverflow bug