Added proper quit function

Resolves #49