fixed finalize bug, added comments.