fixing bugs, and adding features. cleanup now works satisfactorily.