Improved error server shutdown handling
Added basic testing