first re-implementation with prototype classes