Fixed median/percentiles and basic bugs