Added self test code as Joel suggested.