general code cleanup, added command-line arguments to BuildCodebook