Started adding final pattern code

Has not been tested. Looping code not implemented.