Fix some tests and add check for valid args for encode