Various bugs fixes