Reduce duplicate code, fix content-type check.