fixes #4 #5 #12 remove leaks