Rewrite some code, dropped some deprecated code