refactored javascript using Klass