add first test and fix a couple bugs