Cleaned up some code and stabilized some life cycle problems