Refactoring to ts