switched implementation to TypeScript