Fixed memory leaks and a bug in keytometa #32