Among other things, modified to be compatible with Java <1.8