Stuff from C++ to be ported to Java