added test framework and fixed various bugs