Code cleanup, almost ready to submit