Removed useless cleanup code and added actual cleanup