remove unused functions
cleanup
some more cleanup
fix two memory leaks