Fixed some build bugs. Fix output errors. Added simple test.