tests for kbucket and some code cleanup