Big refactor to share more code.

The client and the indexer folders have been made. The common code between them
sits in the het folder. Pending bucket count has also been added and ssome bugs
have been fixed