add basic test and minor refactor