made the code simpler and made it possible to use prototype style coding

Please merge this.