fixed some multithreading issues, wrote an external C function, implemented drake validation 4/21/14