Refine test and fix bug in prototype testing. Prepare for MATLAB upload.