rewrite to more better use of prototypes and object inheritance