mem leak fix + minor features