Rewrote the javascript using TypeScript!