Rewrite all code to typescript