Many changes!

Bug fixes, implementation of a shutdown listener, etc