start to rewrite functions