fixed issues and implemented using prototype