Free some memory
Added java library
Added locks, cleanup