Added tool.h and wrap and unwrap functions