Cleaning up code #3 and added cyclic scanning.