remove unnecessary stuff and remove empty meta and params without an extra iteration