Cleaned up code and added finalization message