Imported code from julia/extras