Rewritten for using the shift registers