Port to 3.4 and moved code into one file