Refactored scoping and events to pubsub

Refactored scoping for individual library files, to use call(this), for
better control. Also removed events and created pubsub.